<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <meta HTTP-EQUIV="Expires" CONTENT="0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>电子公示信息发布</title>
<style type="text/css">
	@import "../dojo-release-1.5.0/dijit/themes/tundra/tundra.css";
	@import "../dojo-release-1.5.0/dojo/resources/dojo.css";
	@import "../dojo-release-1.5.0/dojox/grid/resources/tundraGrid.css";
</style>
<script type="text/javascript" src="../dojo-release-1.5.0/dojo/dojo.js" djConfig="parseOnLoad:true"></script>
<script type="text/javascript" src="../framework/uiutil.js"></script>
<script type="text/javascript" src="../framework/simpleCRUDUtil.js"></script>
<script type="text/javascript">

dojo.addOnLoad(function(){
	initDashboardNameSelect();
	dojo.connect(dojo.byId("dashboardName"),"onblur",generateDashboardIssueForm);
});

var dashboardList = {};	//全部公示板对象
var chosedDashboard = null;	//选定的公示板对象

function initDashboardNameSelect(){
	dojo.xhrGet({
		 url:"../bkgrd/getAllDashboard.do",
		 preventCache:true,
		 handleAs:"json",
		 load:function(response){
			 var ps = [];
			 for(var i in response){
				 var n = response[i]["dashboardName"];
				 ps.push({value:n,name:n});
				 dashboardList[n] = response[i];
			 }
			 D.initCombo("dashboardName",ps)
		 }
	});
}
//生成表单
function generateDashboardIssueForm(){
	dojo.empty("infoDiv");
	var dashboardName = D.getComboValue("dashboardName");
	chosedDashboard = dashboardList[dashboardName];
	var schemes = chosedDashboard["scheme"].split(",");
	var html = "<table>";
	for(var i=0;i<schemes.length;i++){
		var label = schemes[i];
		var id = "infoField_"+i;
		html += ("<tr><td>"+label+'</td><td><input type="text" dojoType="dijit.form.TextBox" trim="true" id="'+id+'"/></td></tr>');
	}
	dojo.byId("infoDiv").innerHTML = html;
}

function issue(){
	if(chosedDashboard == null){
		alert("木有东西可发布咧");
		return;
	}
	var infoStr = "";
	var schemes = chosedDashboard["scheme"].split(",");
	for(var i=0;i<schemes.length;i++){
		var label = schemes[i];
		var id = "infoField_"+i;
		infoStr += (label+":"+dojo.byId(id).value+",")
	}
	dojo.xhrPost({
		 url:"../bkgrd/issueInfoToDashboard.do",
		 encoding : 'UTF-8',
		 preventCache:true,
		 content:{
			 dashboardName:chosedDashboard["dashboardName"],
			 infoItemListStr:infoStr
		 },
		 handleAs:"text",
		 load:function(response){
			 alert(response);
		 }
	});
}
</script>
</head>
<body class="tundra">
选择公示板：<select dojoType="dijit.form.ComboBox" id="dashboardName" value="" required="true" ></select><button dojoType="dijit.form.Button">确定</button>
<hr/>
<div id="infoDiv">

</div>

<button dojoType="dijit.form.Button" id="issueBtn" onclick="issue()" >发布</button>

</body>
</html>